package com.qf.service.impl;

import com.qf.dao.HouseInfoDao;
import com.qf.pojo.HouseInfo;
import com.qf.pojo.UserInfo;
import com.qf.pojo.resp.BaseResult;
import com.qf.service.HouseService;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

@Service
public class HouseServiceImpl implements HouseService {
    BaseResult baseResult = new BaseResult();
    @Resource
    HouseInfoDao houseInfoDao;

    @Override
    public BaseResult findHouseByUid(Integer uid) {
        baseResult.setCode(1);
        baseResult.setInfo("成功");
        baseResult.setData(houseInfoDao.findHouseByUid(uid));
        return baseResult;
    }

    @Override
    public BaseResult findAllHouse() {
        baseResult.setCode(1);
        baseResult.setInfo("成功");
        baseResult.setData(houseInfoDao.findAllHouse());
        return baseResult;
    }

    @Override
    public BaseResult addHouse(HouseInfo houseInfo, HttpSession session) {

        baseResult.setCode(1);
        baseResult.setInfo("成功");
        UserInfo userInfo = (UserInfo) session.getAttribute("user");

        houseInfo.setUid(userInfo.getId());
        //System.out.println(houseInfo);
        houseInfoDao.addHouse(houseInfo);

        //System.out.println(userInfo+"------------");
        //houseInfo.setUid(1);
        //System.out.println(houseInfo+".............");
        baseResult.setData(houseInfo);

        return baseResult;
    }

    @Override
    public BaseResult updateHouse(HouseInfo houseInfo) {
        baseResult.setCode(1);
        baseResult.setInfo("成功");
        baseResult.setData(houseInfoDao.updateHouse(houseInfo));
        return baseResult;
    }

    @Override
    public BaseResult deleteHouseByHid(Integer hid) {
        baseResult.setCode(1);
        baseResult.setInfo("成功");
        baseResult.setData(houseInfoDao.deleteHouseByHid(hid));
        return baseResult;
    }
}
